package com.dankegongyu.shell.js;

import android.graphics.Bitmap;

import com.dankegongyu.component.jsbridge.config.DKWebService;
import com.dankegongyu.component.jsbridge.config.DKWebServiceManager;
import com.dankegongyu.component.jsbridge.listener.DKWebCallback;
import com.dankegongyu.component.jsbridge.listener.DKWebViewClientCallback;
import com.tencent.smtt.sdk.WebView;

/**
 * Created by Admin on 2018/5/7.
 */
public class DKWebClient extends DKWebViewClientCallback {

    private String serviceKey;
    private DKWebService webService;
    private DKWebCallback callback;

    public DKWebClient(String key) {
        this.serviceKey = key;
        webService = DKWebServiceManager.getInstance().get(serviceKey);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        callback = webService.getCallback();
        if (callback != null) {
            callback.setNavigationMenus(null);
        }
    }

    @Override
    public void onPageFinished(WebView webView, String url) {
        super.onPageFinished(webView, url);

        callback = webService.getCallback();
        if (callback != null) {
            if (webView.canGoBack()) {
                callback.refreshCloseBtn(true);
            } else {
                callback.refreshCloseBtn(false);
            }
        }

    }

}
